//
//  YZUserLoginController.m
//  实战项目之登录
//
//  Created by Liu on 16/5/9.
//  Copyright © 2016年 Liu. All rights reserved.
//

#import "YZUserLoginController.h"
#import "YZUserTextFieldView.h"


@interface YZUserLoginController ()<UITextFieldDelegate>

/**
 *  用户名
 */
@property (weak, nonatomic) IBOutlet YZUserTextFieldView *userNameTextField;

/**
 *  密码
 */
@property (weak, nonatomic) IBOutlet YZUserTextFieldView *userPasswordTextField;


/**
 *  文本左边的UIImageView->userName
 */
@property (nonatomic , strong ) UIImageView *userNameLeftImageView;

/**
 *  文本左边的UIImageView->userpassword
 */
@property (nonatomic , strong ) UIImageView *passwordLeftImageView;





/**
 *  通过短信验证码登录
 */
- (IBAction)SMSBtnDidClock;

/**
 *  登录按钮的点击
 */
- (IBAction)loginBtnDidClock;

@end

@implementation YZUserLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置 用户名 和 密码 界面
    [self settingUI];
    self.userNameTextField.delegate = self;
    self.userPasswordTextField.delegate = self;
    self.userNameTextField.clearButtonMode = UITextFieldViewModeAlways;
    self.userPasswordTextField.clearButtonMode = UITextFieldViewModeAlways;
    

}



/**
 *  设置 用户名 和 密码 界面
 */
-(void)settingUI {

    
}


/**
 *  通过短信验证码登录
 */
- (IBAction)SMSBtnDidClock {
    
}

/**
 *  登录按钮的点击
 */
- (IBAction)loginBtnDidClock {
    // hm:123
    // 隐藏键盘
    [self.view endEditing:YES];
    // 获得账号
    NSString *account = self.userNameTextField.text;
    if (![account isEqualToString:@"11"]) {
//        [MBProgressHUD showError:@"账号错误"]; // 默认是主窗口
        printf("账号错了 小伙子");
        return;
    }
    // 获得密码
    NSString *password = self.userPasswordTextField.text;
    if (![password isEqualToString:@"11"]) {
//        [MBProgressHUD showError:@"密码错误"];
        printf("密码错了 小伙子");
        return;
    }
    
    // 密码和账号都是正确的->跳转界面
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        //跳转界面 跳呀跳呀跳呀跳
        
        // performSegueWithIdentifier方法必须由来源控制器调用
        //        [self performSegueWithIdentifier:@"UserLogin" sender:account];
        
        [self finishedLogin];
    });
}

/**
     ake 2016.05.11添加
     代码功能: 登录验证成功 , 返回 TopViewController ,
     同时登录状态 self.hasLogin 发生改变.
 */
#pragma mark - 成功登录后 , 进行跳转
-(void)finishedLogin{
    [self.navigationController popToRootViewControllerAnimated:YES];
    //发布通知改变登录状态
    [[NSNotificationCenter defaultCenter]postNotificationName:@"finishedLogin" object:self];
}

#pragma mark - UITextFieldDelegate


#pragma mark - 懒加载


@end
